/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.devin.avatar.module.system.entity;

import java.util.Date;

import com.devin.avatar.common.config.Global;
import com.devin.avatar.common.entity.DataEntity;
import com.fasterxml.jackson.annotation.JsonFormat;

public class SysUser extends DataEntity {

    private static final long serialVersionUID = 1L;
    // private Office company; // 归属公司
    // private Office office; // 归属部门
    private String loginName;// 登录名
    private String password;// 密码
    private String no; // 工号
    private String name; // 姓名
    private String email; // 邮箱
    private String phone; // 电话
    private String mobile; // 手机
    private String userType;// 用户类型
    private String loginIp; // 最后登陆IP
    private Date loginDate; // 最后登陆日期
    private String loginFlag; // 是否允许登陆
    private String photo; // 头像

    private String oldLoginName;// 原登录名
    private String newPassword; // 新密码

    private String oldLoginIp; // 上次登陆IP
    private Date oldLoginDate; // 上次登陆日期

    // private Role role; // 根据角色查询用户条件

    // private List<Role> roleList = Lists.newArrayList(); // 拥有角色列表

    public SysUser() {
	super();
	this.loginFlag = Global.YES;
    }

    public String getPhoto() {
	return photo;
    }

    public void setPhoto(String photo) {
	this.photo = photo;
    }

    public String getLoginFlag() {
	return loginFlag;
    }

    public void setLoginFlag(String loginFlag) {
	this.loginFlag = loginFlag;
    }

    public String getId() {
	return id;
    }

    public String getLoginName() {
	return loginName;
    }

    public void setLoginName(String loginName) {
	this.loginName = loginName;
    }

    public String getPassword() {
	return password;
    }

    public void setPassword(String password) {
	this.password = password;
    }

    public String getName() {
	return name;
    }

    public String getNo() {
	return no;
    }

    public void setNo(String no) {
	this.no = no;
    }

    public void setName(String name) {
	this.name = name;
    }

    public String getEmail() {
	return email;
    }

    public void setEmail(String email) {
	this.email = email;
    }

    public String getPhone() {
	return phone;
    }

    public void setPhone(String phone) {
	this.phone = phone;
    }

    public String getMobile() {
	return mobile;
    }

    public void setMobile(String mobile) {
	this.mobile = mobile;
    }

    public String getUserType() {
	return userType;
    }

    public void setUserType(String userType) {
	this.userType = userType;
    }

    public Date getCreateDate() {
	return createDate;
    }

    public String getLoginIp() {
	return loginIp;
    }

    public void setLoginIp(String loginIp) {
	this.loginIp = loginIp;
    }

    public Date getLoginDate() {
	return loginDate;
    }

    public void setLoginDate(Date loginDate) {
	this.loginDate = loginDate;
    }

    public String getOldLoginName() {
	return oldLoginName;
    }

    public void setOldLoginName(String oldLoginName) {
	this.oldLoginName = oldLoginName;
    }

    public String getNewPassword() {
	return newPassword;
    }

    public void setNewPassword(String newPassword) {
	this.newPassword = newPassword;
    }

    public String getOldLoginIp() {
	if (oldLoginIp == null) {
	    return loginIp;
	}
	return oldLoginIp;
    }

    public void setOldLoginIp(String oldLoginIp) {
	this.oldLoginIp = oldLoginIp;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getOldLoginDate() {
	if (oldLoginDate == null) {
	    return loginDate;
	}
	return oldLoginDate;
    }

    public void setOldLoginDate(Date oldLoginDate) {
	this.oldLoginDate = oldLoginDate;
    }

    public boolean isAdmin() {
	return isAdmin(this.id);
    }

    public static boolean isAdmin(String id) {
	return id != null && "1".equals(id);
    }

    @Override
    public String toString() {
	return id;
    }
}